home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr27 / gs26.zip / GS_LEV2.PS < prev    next >
Text File  |  1993-05-01  |  12KB  |  406 lines

  1. %    Copyright (C) 1990, 1991, 1992 Aladdin Enterprises.  All rights reserved.
  2. %    Distributed by Free Software Foundation, Inc.
  3. %
  4. % This file is part of Ghostscript.
  5. %
  6. % Ghostscript is distributed in the hope that it will be useful, but
  7. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. % to anyone for the consequences of using it or for whether it serves any
  9. % particular purpose or works at all, unless he says so in writing.  Refer
  10. % to the Ghostscript General Public License for full details.
  11. %
  12. % Everyone is granted permission to copy, modify and redistribute
  13. % Ghostscript, but only under the conditions described in the Ghostscript
  14. % General Public License.  A copy of this license is supposed to have been
  15. % given to you along with Ghostscript so you can know your rights and
  16. % responsibilities.  It should be in a file named COPYING.  Among other
  17. % things, the copyright notice and this notice must be preserved on all
  18. % copies.
  19.  
  20. % Initialization file for Level 2 functions.
  21. % When this is run, systemdict is still writable,
  22. % but everything defined here goes into level2dict.
  23.  
  24. level2dict begin
  25.  
  26. % ------ Miscellaneous ------ %
  27.  
  28. (<<) cvn /mark load def
  29. (>>) cvn /dicttomark load odef
  30. /currentsystemparams { mark .currentsystemparams dicttomark } odef
  31. /currentuserparams { mark .currentuserparams dicttomark } odef
  32. /deviceinfo { currentdevice getdeviceprops dicttomark } odef
  33. /globaldict currentdict /shareddict .knownget not { 20 dict } if def
  34. /glyphshow where {pop (%END glyphshow) .skipeof} if
  35.     % The following was contributed by a user....
  36. /glyphshow {
  37.     % Reencode the font, placing glyph of interest in position 0,
  38.     % then show it.
  39.     save    % So can reclaim VM from reencoding
  40.     currentfont /Encoding get dup length array copy dup 0 5 -1 roll put
  41.     currentfont
  42.     dup maxlength dict copy dup /FID undef
  43.     dup /Encoding 4 -1 roll put
  44.     () exch definefont setfont
  45.     (\000) show
  46.     currentpoint 3 -1 roll % Track movement due to show across restore
  47.     restore
  48.     moveto
  49. } odef
  50. %END glyphshow
  51. /realtime /usertime load def
  52.  
  53. % ------ Painting ------ %
  54.  
  55. % A straightforward definition of execform that doesn't actually
  56. % do any caching.
  57. /execform
  58.  { dup /Implementation known not
  59.     { dup /FormType get 1 ne { /rangecheck signalerror } if
  60.       dup /Implementation null put readonly
  61.     } if
  62.    gsave dup /Matrix get concat
  63.    dup /BBox get aload pop
  64.    exch 3 index sub exch 2 index sub rectclip
  65.    dup /PaintProc get exec
  66.    grestore
  67.  } odef
  68.  
  69. /setpattern
  70.  { currentcolorspace 0 get /Pattern ne
  71.     { [ /Pattern currentcolorspace ] setcolorspace
  72.     } if
  73.    setcolor
  74.  } odef
  75.  
  76. % ------ Virtual memory ------ %
  77.  
  78. /currentglobal /currentshared load def
  79. /gcheck /scheck load def
  80. /globaldict /shareddict load def
  81. /setglobal /setshared load def
  82.  
  83. % ------ Resources ------ %
  84.  
  85. % Currently, we don't implement resource unloading (there wouldn't be
  86. % much value to it without garbage collection) or global/local
  87. % instance sets (since we don't have a global/local memory distinction.)
  88.  
  89. % Note that the dictionary that defines a resource category is stored
  90. % in global memory.  The PostScript manual says that each category must
  91. % manage global and local instances separately.  However, objects in
  92. % global memory can't reference objects in local memory.  This means
  93. % that the resource category dictionary, which would otherwise be the
  94. % obvious place to keep track of the instances, can't be used to keep
  95. % track of local instances.  Instead, there must be a parallel
  96. % structure in local memory for each resource category.  Needless to
  97. % say, we haven't implemented this yet.
  98.  
  99. % We keep track of instances in another entry in the resource dictionary,
  100. % called Instances.  For categories with implicit instances,
  101. % the values in Instances are the same as the keys; for other categories,
  102. % the values are [instance status size].
  103.  
  104. % Define the Category category, except for most of the procedures.
  105. % The dictionary we're about to create will become the Category
  106. % category definition dictionary.
  107.  
  108. 10 dict begin
  109. /Category /Category def
  110. /.CheckResource
  111.     { true        % dup gcheck currentglobal and
  112.        { /DefineResource /FindResource /ResourceForAll /ResourceStatus
  113.          /UndefineResource }
  114.        { 2 index exch known and }
  115.       forall exch pop
  116.     } bind def
  117. /DefineResource
  118.     { dup .CheckResource
  119.        { dup /Category 3 index put
  120.          dup [ exch 0 -1 ] exch
  121.          Instances 4 2 roll put
  122.        }
  123.        { /typecheck signalerror
  124.        }
  125.       ifelse
  126.     } bind def
  127. /FindResource        % (redefined below)
  128.     { Instances exch get 0 get
  129.     } bind def
  130. /Instances 25 dict def
  131. /InstanceType /dicttype def
  132.  
  133. Instances /Category [currentdict 0 -1] put
  134. Instances end begin    % so we can name the Category definition
  135.  
  136. % Define the resource operators.  I don't see how we can possibly restore
  137. % the stacks after an error, since the procedure may have popped and
  138. % pushed elements arbitrarily....
  139.  
  140. mark
  141. /defineresource
  142.     { /Category findresource dup begin
  143.       /InstanceType known
  144.        { dup type InstanceType ne
  145.          { dup type /packedarraytype eq InstanceType /arraytype eq and
  146.             not { /typecheck signalerror } if } if } if
  147.       /DefineResource load stopped end { stop } if
  148.     }
  149. /findresource
  150.     { dup /Category eq
  151.        { pop //Category 0 get } { /Category findresource } ifelse
  152.       begin
  153.       /FindResource load stopped end { stop } if
  154.     }
  155. /resourceforall
  156.     { /Category findresource begin
  157.       /ResourceForAll load stopped end { stop } if
  158.     }
  159. /resourcestatus
  160.     { /Category findresource begin
  161.       /ResourceStatus load stopped end { stop } if
  162.     }
  163. /undefineresource
  164.     { /Category findresource begin
  165.       /UndefineResource load stopped end { stop } if
  166.     }
  167. end        % Instances
  168. counttomark 2 idiv { bind odef } repeat pop
  169.  
  170. % Define the Generic category.
  171.  
  172. /Generic mark
  173.  
  174. /Instances 0 dict
  175. /.CheckResource        % not a standard entry
  176.     { pop true
  177.     } bind
  178. /DefineResource
  179.     { dup .CheckResource
  180.        { { readonly } stopped pop
  181.          dup [ exch 0 -1 ] exch
  182.          Instances 4 2 roll .growput
  183.        }
  184.        { /typecheck signalerror
  185.        }
  186.       ifelse
  187.     } bind
  188. /FindResource
  189.     { dup ResourceStatus
  190.        { pop 1 gt        % not in VM
  191.           { dup vmstatus pop exch pop exch
  192.             .LoadResource
  193.         vmstatus pop exch pop exch sub
  194.         Instances 2 index get
  195.         dup 1 1 put
  196.         2 3 -1 roll put
  197.           }
  198.          if
  199.          Instances exch get 0 get
  200.        }
  201.        { /undefinedresource signalerror
  202.        }
  203.       ifelse
  204.     } bind
  205. /.LoadResource        % not a standard entry; may fail
  206.     { .ResourceFile run
  207.     } bind
  208. /.ResourceFile        % not a standard entry; may fail
  209.     { currentdict /ResourceFileName get 100 string exch exec
  210.       findlibfile { exch pop } { (r) file } ifelse    % let the error happen
  211.     } bind
  212. /.ResourceFileDict    % not a standard entry
  213.     0 dict
  214. /ResourceFileName    % leave a slot
  215.     { exch dup .ResourceFileDict exch .knownget
  216.        { exch pop exch copy }
  217.        { exch pop /undefinedresource signalerror }
  218.       ifelse
  219.     } bind
  220. /ResourceForAll
  221.     { % We construct a new procedure so we don't have to use
  222.       % static resources to hold the iteration state.
  223.       3 packedarray        % template, proc, scratch
  224.       { exch pop    % stack contains: key, {template, proc, scratch}
  225.         2 copy 0 get stringmatch
  226.          { 1 index type dup /stringtype eq exch /nametype eq or
  227.             { 2 copy 2 get cvs
  228.           exch 1 get 3 -1 roll pop
  229.         }
  230.         { 1 get
  231.         }
  232.            ifelse exec
  233.          }
  234.          { pop pop
  235.          }
  236.         ifelse
  237.       } /exec cvx 3 packedarray cvx
  238.       Instances exch forall
  239.     } bind
  240. /ResourceStatus
  241.     { dup Instances exch .knownget
  242.        { exch pop dup 1 get exch 2 get true }
  243.        { mark exch { .ResourceFile } stopped
  244.           { cleartomark false } { closefile cleartomark 2 -1 true }
  245.          ifelse
  246.        }
  247.       ifelse
  248.     } bind
  249. /UndefineResource
  250.     { dup Instances exch .knownget
  251.        { dup 1 get 1 ge
  252.           { dup 0 null put 1 2 put pop }
  253.           { pop Instances exch undef }
  254.          ifelse
  255.        }
  256.        { pop
  257.        }
  258.       ifelse
  259.     } bind
  260.  
  261. % We're still running in Level 1 mode, so dictionaries won't expand.
  262. % Leave room for the /Category entry.
  263. /Category null
  264.  
  265. dicttomark
  266. /Category defineresource pop
  267.  
  268. % Fill in the rest of the Category category.
  269. /Category /Category findresource dup
  270. /Generic /Category findresource begin
  271.  { /FindResource /ResourceStatus /ResourceForAll }
  272.  { dup load put dup } forall
  273. pop pop end
  274.  
  275. % Define the fixed categories.
  276.  
  277. mark
  278.     % Things other than types
  279.  /ColorSpaceFamily
  280.    {/CIEBaseA /CIEBasedABC /DeviceCMYK /DeviceGray /DeviceRGB
  281.     /Indexed /Separation        % no Pattern yet
  282.    }
  283.  /Emulator
  284.    {}
  285.  /Filter
  286.    [ systemdict
  287.      { pop =string cvs (.filter_) anchorsearch
  288.         { pop cvn }
  289.         { pop }
  290.        ifelse
  291.      }
  292.     forall
  293.    ]
  294.  /IODevice
  295.    {(%os%)}
  296.     % Types
  297.  /ColorRenderingType
  298.    {1}
  299.  /FMapType
  300.    {2 3 4 5 6 7 8}
  301.  /FontType
  302.    [/.buildfont0 where {pop 0} if 1 3]
  303.  /FormType
  304.    {1}
  305.  /HalftoneType
  306.    {}
  307.  /ImageType
  308.    {1}
  309.  /PatternType
  310.    {}
  311. counttomark 2 idiv
  312.  { 7 dict begin        % 5 procedures, Category, Instances
  313.    /DefineResource
  314.     { /invalidaccess signalerror } bind def
  315.    /FindResource
  316.     { Instances exch get } bind def
  317.    /ResourceForAll
  318.     /Generic /Category findresource /ResourceForAll get def
  319.    /ResourceStatus
  320.     { Instances exch known { 0 0 true } { false } ifelse } bind def
  321.    /UndefineResource
  322.     { /invalidaccess signalerror } bind def
  323.    dup length dict dup begin exch { dup def } forall end readonly
  324.    /Instances exch def
  325.    currentdict end /Category defineresource pop
  326.  } repeat pop
  327.  
  328. % Define the other built-in categories.
  329.  
  330. mark
  331.   /ColorRendering /dicttype /ColorSpace /arraytype /Encoding /arraytype
  332.   /Font /dicttype /Form /dicttype /Halftone /dicttype /Pattern /dicttype
  333.   /ProcSet /dicttype
  334. counttomark 2 idiv
  335.  { /Generic /Category findresource dup maxlength 1 add dict copy begin
  336.    /InstanceType exch def
  337.    /Instances 10 dict def
  338.    currentdict end /Category defineresource pop
  339.  } repeat pop
  340.  
  341. % Complete the Encoding category.
  342.  
  343. /findencoding
  344.     { /Encoding findresource } odef
  345.  
  346. /Encoding /Category findresource begin
  347. % Handle SymbolEncoding, which is loaded lazily, specially.
  348. Instances /SymbolEncoding [null 2 -1] put
  349. /.ResourceFileDict
  350.     mark
  351.       /SymbolEncoding (gs_sym_e.ps)
  352.     dicttomark def
  353. end
  354.  
  355. /ISOLatin1Encoding ISOLatin1Encoding /Encoding defineresource pop
  356. /StandardEncoding StandardEncoding /Encoding defineresource pop
  357. /SymbolEncoding { /SymbolEncoding findencoding } bind def
  358.  
  359. (%END of level2dict) .skipeof    %****************
  360.  
  361. % Complete the Font category.
  362.  
  363. /Font /Category findresource begin
  364. currentdict /..definefont /definefont load .growput
  365. currentdict /..findfont /findfont load .growput
  366. /DefineResource
  367.     { 2 copy ..definefont exch pop
  368.       dup [exch 0 -1] exch
  369.       Instances 4 2 roll .growput
  370.     } bind def
  371. /.LoadResource
  372.     { ..findfont pop
  373.     } bind def
  374. end
  375. % Make entries for all known fonts.
  376. /.resourceFromFontmap
  377.  { /Font /Category findresource begin
  378.    Fontmap
  379.     { pop dup Instances exch known
  380.        { pop }
  381.        { [null 2 -1] Instances 3 1 roll .growput }
  382.       ifelse
  383.     }
  384.    forall
  385.    end
  386.  } bind def
  387. .resourceFromFontmap
  388. /Font /Category findresource begin
  389. FontDirectory
  390.  { Instances 3 1 roll [exch 0 -1] .growput
  391.  }
  392. forall end
  393. /..loadFontmap /.loadFontmap load def
  394. /.loadFontmap { ..loadFontmap .resourceFromFontmap } def
  395.  
  396. /definefont
  397.     { /Font defineresource } bind def
  398. /findfont
  399.     { /Font findresource } bind def
  400. /undefinefont
  401.     { /Font undefineresource } bind def
  402.  
  403. %END of level2dict
  404.  
  405. end
  406.